package com.stylefeng.guns.modular.wz.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.common.persistence.model.WzAnswer;
import com.stylefeng.guns.modular.wz.service.IWzAnswerService;

/**
 * 答案控制器
 *
 * @author fengshuonan
 * @Date 2018-03-17 09:53:38
 */
@Controller
@RequestMapping("/wzAnswer")
public class WzAnswerController extends BaseController {

    private String PREFIX = "/wz/wzAnswer/";

    @Autowired
    private IWzAnswerService wzAnswerService;

    /**
     * 跳转到答案首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "wzAnswer.html";
    }

    /**
     * 跳转到添加答案
     */
    @RequestMapping("/wzAnswer_add")
    public String wzAnswerAdd() {
        return PREFIX + "wzAnswer_add.html";
    }

    /**
     * 跳转到修改答案
     */
    @RequestMapping("/wzAnswer_update/{wzAnswerId}")
    public String wzAnswerUpdate(@PathVariable Long wzAnswerId, Model model) {
        WzAnswer wzAnswer = wzAnswerService.selectById(wzAnswerId);
        model.addAttribute("item",wzAnswer);
        LogObjectHolder.me().set(wzAnswer);
        return PREFIX + "wzAnswer_edit.html";
    }

    /**
     * 获取答案列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return wzAnswerService.selectList(null);
    }

    /**
     * 新增答案
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(WzAnswer wzAnswer) {
        wzAnswerService.insert(wzAnswer);
        return super.SUCCESS_TIP;
    }

    /**
     * 删除答案
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long wzAnswerId) {
        wzAnswerService.deleteById(wzAnswerId);
        return SUCCESS_TIP;
    }

    /**
     * 修改答案
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(WzAnswer wzAnswer) {
        wzAnswerService.updateById(wzAnswer);
        return super.SUCCESS_TIP;
    }

    /**
     * 答案详情
     */
    @RequestMapping(value = "/detail/{wzAnswerId}")
    @ResponseBody
    public Object detail(@PathVariable("wzAnswerId") Long wzAnswerId) {
        return wzAnswerService.selectById(wzAnswerId);
    }
}
